<template>
  <div id="windowSettingManage" class="windowEditorTab">
    <el-form :model="form_function_choice" label-width="100px">
      <el-form-item label="GiteeToken">
        <el-input v-model="form_function_choice.access_token" placeholder="输入GiteeAPI授权码">
          <template #append>
            <el-link :underline="false" target="_blank"
                     href="https://gitee.com/profile/personal_access_tokens">
              获取授权码
            </el-link>
          </template>
        </el-input>
      </el-form-item>
      <el-form-item label="分析地址">
        <el-input v-model="form_function_choice.rpm_repo_parse_link" placeholder="输入RPM包仓库分析地址">
        </el-input>
      </el-form-item>
      <el-form-item label="打包地址">
        <el-input v-model="form_function_choice.rpm_package_server_link" placeholder="输入RPM目录打包地址">
        </el-input>
      </el-form-item>
      <el-form-item label="打包后端地址">
        <el-input v-model="form_function_choice.rpm_package_server_link_host"
                  placeholder="输入RPM目录打包地址，mock地址">
          <template #append>
            <el-input v-model="form_function_choice.rpm_package_server_link_username"
                      placeholder="输入用户名">
              <template #append>
                <el-input v-model="form_function_choice.rpm_package_server_link_password" type="password"
                          placeholder="输入密码"></el-input>
              </template>
            </el-input>
          </template>
        </el-input>
      </el-form-item>
      <el-form-item label="单包源分析">
        <el-input v-model="form_function_choice.single_package_source_link" placeholder="输入单包源分析地址">
        </el-input>
      </el-form-item>
      <el-form-item label="兼容性分析">
        <el-input v-model="form_function_choice.api_compatibility_report_generate" placeholder="输入兼容性分析地址">
        </el-input>
      </el-form-item>
    </el-form>
    <el-space wrap spacer="|">
      <el-button type="success" @click="session_setting_write">保存设置</el-button>
      <el-button type="danger" @click="session_setting_read">加载设置</el-button>
    </el-space>
  </div>
</template>

<script>
import axios from 'axios'
import {ElNotification} from 'element-plus'
// import {Unlock, Lock} from '@element-plus/icons-vue'

export default {
  name: "windowSettingManage",
  props: {
    sessionToken: String
  },
  components: {
    // Unlock,
    // Lock,
  },
  data() {
    return {

      sessionMockList: ["sp1", "sp2", "sp2_shao"],
      form_function_choice: {
        is_session_init: false,
        is_code_name_lock: false,
        is_setting_auto_sync: "关闭同步",
        access_token: '',
        rpm_repo_parse_link: '',
        username: "",
        changelog_title: "",
        branch_list: [],
        branch_choice: ["openEuler-20.03-LTS-SP1"],
        codeName: '',
        cve_number: "",
        sessionMockChoice: '',
        file_download_link: '',
        rpmbuild_compile_type: '',
        rpmbuild_koji_choice: [],
        tag_237: "v10-sp1.1-updates",
        tag_238: "v10-sp2-updates",
        tag_239: "v10-sp2-updates-5000xxx",
        tag_242: "ns8.6",
        func_btn_activate_name: "1",
        rpm_package_server_link: "",
        rpm_package_server_link_host: "",
        rpm_package_server_link_username: "",
        rpm_package_server_link_password: "",
        single_package_source_link: "",
        api_compatibility_report_generate: "",
      }
    }
  },
  methods: {
    //获取分支：https://gitee.com/api/v5/repos/src-openeuler/rpm/branches
    refresh_gitee_token() {
      // https://gitee.com/oauth/authorize?client_id=8ac7a94ff19ddb4b9d267d525c048e2845f589cf3b1e8d09ef2568ca63f74603&response_type=code
      // https://gitee.com/oauth/token?grant_type=refresh_token&refresh_token={refresh_token}
      // let url = "https://gitee.com/oauth/token?grant_type=refresh_token&refresh_token=" + this.form_function_choice.access_token
      let url = "https://gitee.com/oauth/authorize?client_id=8ac7a94ff19ddb4b9d267d525c048e2845f589cf3b1e8d09ef2568ca63f74603&response_type=code"
      axios.get(url).then(function (response) {
        console.log(response)
      }).catch(function (error) { // 请求失败处理
        console.log(error);
        ElNotification({title: "GiteeAPI请求失败，重新获取授权码", type: 'error',})
      });
    },
    is_in_list(v, list) {
      return list.includes(v)
    },
    session_init() {
      let obj_this = this
      let data = {
        "session_token": obj_this.sessionToken,
        "session_function": "session_init"
      }
      axios.post('/session_function_do', data).then(function (response) {
        obj_this.form_function_choice.is_session_init = true
        obj_this.session_setting_write()
        console.log(response)
      }).catch(function (error) { // 请求失败处理
        console.log(error);
      });
    },
    session_setting_write() {
      let obj_this = this
      let data = {
        "session_token": obj_this.sessionToken,
        "session_function": "session_setting_write",
        "session_setting": obj_this.form_function_choice
      }
      axios.post('/session_function_do', data).then(function () {
        obj_this.$store.state.obj_mainWindow.session_setting_read(obj_this.session_setting_read)
      }).catch(function (error) { // 请求失败处理
        console.log(error);
      });
    },
    session_setting_read() {
      Object.assign(this.form_function_choice, this.$store.state.obj_setting_map)
    },
  },
  created() {
    this.session_setting_read()
  },
  watch: {}
}
</script>

<style scoped>
</style>